package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {

    @Autowired
    public UserService userService;


    @RequestMapping("/findAll")
    public String findAll(Model model){
        //1查询用户类表信息
        List<User> userList=userService.findAll();
        //2将数据保存到request 域 对象中之后返回给用户  视图渲染过程
        model.addAttribute("userList", userList);
       return "userList";
    }
    /*
    * 实现页面的跳转
    * url地址：
    * 跳转页面
    * */
    @RequestMapping("/ajax")
    public String ajax(){
        return "ajax";
    }
    /*
    * 实现ajax业务调用
    * http://localhost:8080/findAll:id=40
    *
    * */
    @RequestMapping("/findAll")
    @ResponseBody     //ajax结束标示
    public List<User> findAjax(){
        return userService.findAll();
    }
}









